package gek.uni.diplom.ocl.example.utils;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EParameter;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.ocl.OCL;
import org.eclipse.ocl.Query;
import org.eclipse.ocl.ecore.CallOperationAction;
import org.eclipse.ocl.ecore.Constraint;
import org.eclipse.ocl.ecore.SendSignalAction;
import org.eclipse.ocl.expressions.OCLExpression;
import org.eclipse.ocl.expressions.OperationCallExp;

public class OclEcoreUtils {

  public static Object evaluateExpression(
      OCLExpression<EClassifier> expression,
      OCL<EPackage, EClassifier, EOperation, EStructuralFeature, EEnumLiteral, EParameter, EObject, CallOperationAction, SendSignalAction, Constraint, EClass, EObject> ocl) {

    Query<EClassifier, EClass, EObject> query = ocl.createQuery(expression);
    return query.evaluate();
  }

  public static boolean checkIsLeafExp(
      OperationCallExp<EClassifier, EOperation> callExp) {
    Object containerObj = callExp.eContainer();
    if (containerObj == null)
      return true;
    else
      return false;
    // if (false == containerObj instanceof OperationCallExp) {
    // return false;
  }

//  public static void copyPatternInitSections(VariableExpCodeNode pattern, String srcOclStr,
//      String targetOclStr) {
//    try{
//      pattern.setGetterInitString(targetOclStr, pattern.getGetterInitString(srcOclStr));
//    } catch (ErrorException e){
//      ErrorManager.addError(e.getMessage());
//    }
////    try{
////      pattern.setGetterCallString(targetOclStr, pattern.getGetterCallString(srcOclStr));
////    } catch (ErrorException e){
////      ErrorManager.addError(e.getMessage());
////    }
//    try{
//      pattern.setSetterInitString(targetOclStr, pattern.getSetterInitString(srcOclStr));
//    } catch (ErrorException e){
//      ErrorManager.addError(e.getMessage());
//    }
////    try{
////      pattern.setSetterCallString(targetOclStr, pattern.getSetterCallString(srcOclStr));
////    } catch (ErrorException e){
////      ErrorManager.addError(e.getMessage());
////    }
//  }
}
